package com.wujunshen.algorithm.leetcode.depth.first.search;

/**
 * @author frank woo(吴峻申) <br>
 *     email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/7/25 12:37<br>
 */
public class 二叉树的最大深度 {
  public int maxDepth(TreeNode1 root) {
    if (root == null) {
      return 0;
    } else {
      int leftHeight = maxDepth(root.left);
      int rightHeight = maxDepth(root.right);
      return Math.max(leftHeight, rightHeight) + 1;
    }
  }
}

class TreeNode1 {
  int val;
  TreeNode1 left;
  TreeNode1 right;

  TreeNode1() {}

  TreeNode1(int val) {
    this.val = val;
  }

  TreeNode1(int val, TreeNode1 left, TreeNode1 right) {
    this.val = val;
    this.left = left;
    this.right = right;
  }
}
